package com.mis.pos.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.mis.pos.base.entity.BaseEntity;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @Description 用户表
 * @Author yuxiang
 * @CreatedDate 2019/10/30 16:03
 */
@Entity
@Table(name = "user")
public class UserEntity extends BaseEntity implements Serializable {

    /**
     * 用户名 ==》唯一
     */
    @Column(unique = true)
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 用户名称
     */
    private String name;

    /**
     * 加密密码的盐
     */
    private String salt;

    /**
     * 用户拥有的角色
     */
    @JsonIgnoreProperties(value = {"userInfos"})
    @ManyToMany // 立即从数据库中进行加载数据(fetch = FetchType.EAGER)
    @JoinTable(name = "SysUserRole", joinColumns = @JoinColumn(name = "userId"), inverseJoinColumns = @JoinColumn(name = "roleId"))
    private List<SysRole> roles; // 一个用户具有多个角色

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public List<SysRole> getRoles() {
        return roles;
    }

    public void setRoles(List<SysRole> roles) {
        this.roles = roles;
    }

    public UserEntity(){}

    public UserEntity(String username, String password, String email) {
        this.username = username;
        this.password = password;
        this.email = email;
    }
}
